import * as actionTypes from "./actionTypes";
import { fromJS } from "immutable"; //把数据转为immutable对象，使用这个使用更要使用gget方法，使用set方法去变更state内容
const defaultState = fromJS({
  menuArr: [],
  ulDate: [],
  ulDate1: [],
  ulDate2: [],
  type: "0",
});
// 导出一个纯函数
export default (state = defaultState, action) => {
  switch (action.type) {
    case actionTypes.getAllIndex:
      let { menuArr, ulDate, ulDate1, ulDate2 } = action.result;
      return state.merge(
        {
          ulDate: fromJS(ulDate),
          ulDate1: fromJS(ulDate1),
          ulDate2: fromJS(ulDate2),
          menuArr: fromJS(menuArr),
        }
      )
    case actionTypes.getUlList:
      let {type ,data}=action.result;
      let udata=[];
      let key="";
      if (Number(type)=== 0) {
          key='ulDate'
         udata= state.get("ulDate").concat(fromJS(data))
      } else if (Number(type)===1) {
        key='ulDate1'
        udata= state.get("ulDate1").concat(fromJS(data))
      }else   {
        key='ulDate2'
        udata= state.get("ulDate2").concat(fromJS(data))
      }
      console.log("1213****((&&",key,udata)
      return state.set(key, udata)
    case actionTypes.setUlListType:
      return state.set("type", action.data)
    // let { menuArr, ulDate } = action.result;
    // return state.set("ulDate", fromJS(action.ulDate)).set("textData", fromJS(action.textData)).set("homeRightUlli", fromJS(action.homeRightUlli));
    default:
      return state;
  }
};
